package xyz.zhouxf.rpc.registry.nacos;



import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import lombok.extern.slf4j.Slf4j;
import xyz.zhouxf.rpc.enumeration.RpcError;
import xyz.zhouxf.rpc.exception.RpcException;
import xyz.zhouxf.rpc.registry.ServiceRegistry;
import xyz.zhouxf.rpc.util.NacosUtil;

import java.net.InetSocketAddress;
import java.util.List;

/**
 * @author zhouxf
 */
@Slf4j
public class NacosServiceRegistry implements ServiceRegistry {

    @Override
    public void register(String serviceName, InetSocketAddress inetSocketAddress) {
        try {
            NacosUtil.registerService(serviceName, inetSocketAddress);
        } catch (NacosException e) {
            log.error("服务注册失败：{}",e);
            throw new RpcException(RpcError.SERVICE_REGISTER_FAILED);
        }
    }

}
